//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "GarmanKlassSigma3.h"
using namespace Cephei::QL::Models::Volatility;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Models::Volatility::CGarmanKlassSigma3::CGarmanKlassSigma3 (Double y, Double marketOpenFraction) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phGarmanKlassSigma3 = NULL;
#endif
        QuantLib::Real _y = (QuantLib::Real)ValueHelper::Convert (y); //d
        QuantLib::Real _marketOpenFraction = (QuantLib::Real)ValueHelper::Convert (marketOpenFraction); //d
        _ppGarmanKlassSigma3 = new boost::shared_ptr<QuantLib::GarmanKlassSigma3> (new QuantLib::GarmanKlassSigma3 ( _y,  _marketOpenFraction ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Models::Volatility::CGarmanKlassSigma3::CGarmanKlassSigma3 (boost::shared_ptr<QuantLib::GarmanKlassSigma3>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phGarmanKlassSigma3 = NULL;
#endif
	_ppGarmanKlassSigma3 = &childNative;
    
}
Cephei::QL::Models::Volatility::CGarmanKlassSigma3::CGarmanKlassSigma3 (QuantLib::GarmanKlassSigma3& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phGarmanKlassSigma3 = NULL;
#endif
	_ppGarmanKlassSigma3 = new boost::shared_ptr<QuantLib::GarmanKlassSigma3> (&childNative);
    
    _GarmanKlassSigma3Owner = owner;
    
}

Cephei::QL::Models::Volatility::CGarmanKlassSigma3::CGarmanKlassSigma3 (CGarmanKlassSigma3^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phGarmanKlassSigma3 = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGarmanKlassSigma3 = new boost::shared_ptr<QuantLib::GarmanKlassSigma3> (copy->GetShared());
        
    }
}
Cephei::QL::Models::Volatility::CGarmanKlassSigma3::CGarmanKlassSigma3 (PLATFORM::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phGarmanKlassSigma3 = NULL;
#endif
	if (!t->IsSubclassOf(CGarmanKlassSigma3::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Models::Volatility::CGarmanKlassSigma3::CGarmanKlassSigma3 (QuantLib::Handle<QuantLib::GarmanKlassSigma3>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phGarmanKlassSigma3 = &childNative;
	_ppGarmanKlassSigma3 = &static_cast<boost::shared_ptr<QuantLib::GarmanKlassSigma3>>(childNative.currentLink());
    
    _GarmanKlassSigma3Owner = owner;
}
Cephei::QL::Models::Volatility::CGarmanKlassSigma3::CGarmanKlassSigma3 (QuantLib::Handle<QuantLib::GarmanKlassSigma3> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phGarmanKlassSigma3 = &childNative;
	_ppGarmanKlassSigma3 = &static_cast<boost::shared_ptr<QuantLib::GarmanKlassSigma3>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Models::Volatility::CGarmanKlassSigma3::CGarmanKlassSigma3 (QuantLib::GarmanKlassSigma3 childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phGarmanKlassSigma3 = NULL;
#endif
	_ppGarmanKlassSigma3 = new boost::shared_ptr<QuantLib::GarmanKlassSigma3> (new QuantLib::GarmanKlassSigma3 (childNative));
    
}
#endif

Cephei::QL::Models::Volatility::CGarmanKlassSigma3::~CGarmanKlassSigma3 ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppGarmanKlassSigma3 != NULL)
    {
	    delete _ppGarmanKlassSigma3;
        _ppGarmanKlassSigma3 = NULL;
    }
}
Cephei::QL::Models::Volatility::CGarmanKlassSigma3::!CGarmanKlassSigma3 ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppGarmanKlassSigma3 != NULL)
    {
	    delete _ppGarmanKlassSigma3;
    }
}
QuantLib::GarmanKlassSigma3& Cephei::QL::Models::Volatility::CGarmanKlassSigma3::GetReference ()
{
    if (_ppGarmanKlassSigma3 == NULL) throw REFNEW NativeNullException ();
	return **_ppGarmanKlassSigma3;
}
boost::shared_ptr<QuantLib::GarmanKlassSigma3>& Cephei::QL::Models::Volatility::CGarmanKlassSigma3::GetShared ()
{
    if (_ppGarmanKlassSigma3 == NULL) throw REFNEW NativeNullException ();
	return *_ppGarmanKlassSigma3;
}
QuantLib::GarmanKlassSigma3* Cephei::QL::Models::Volatility::CGarmanKlassSigma3::GetPointer ()
{
    if (_ppGarmanKlassSigma3 == NULL) throw REFNEW NativeNullException ();
	return &**_ppGarmanKlassSigma3;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GarmanKlassSigma3>& Cephei::QL::Models::Volatility::CGarmanKlassSigma3::GetHandle ()
{
	if (_phGarmanKlassSigma3 == NULL)
	{
		_phGarmanKlassSigma3 = new Handle<QuantLib::GarmanKlassSigma3> (*_ppGarmanKlassSigma3);
	}
	return *_phGarmanKlassSigma3;
}
#endif
bool Cephei::QL::Models::Volatility::CGarmanKlassSigma3::HasNative () 
{
	return (_ppGarmanKlassSigma3 != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Models::Volatility::IGarmanKlassSigma3^ Cephei::QL::Models::Volatility::CGarmanKlassSigma3_Factory::Create (Double y, Double marketOpenFraction)
{
    return REFNEW CGarmanKlassSigma3 ( y,  marketOpenFraction);
}
